package com.hzau.tourist_service_sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzau.tourist_service_sys.dao.FoodRelax.FoodRelaxDao;
import com.hzau.tourist_service_sys.dao.FoodRelax.PerformanceDao;
import com.hzau.tourist_service_sys.pojo.FoodRelax.FoodRelax;
import com.hzau.tourist_service_sys.pojo.FoodRelax.Performance;
import com.hzau.tourist_service_sys.result.Result;
import com.hzau.tourist_service_sys.service.FoodRelaxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
@Transactional
@Service
public class FoodRelaxServiceImpl implements FoodRelaxService {
    @Autowired
    FoodRelaxDao foodRelaxDao;
    @Autowired
    PerformanceDao performanceDao;
    int pagesize = 10;

    @Override
    public Result selectAll(int pagenum) {
        IPage page = new Page(pagenum, 20);
         foodRelaxDao.selectPage(page, null);
        return Result.success(page.getRecords());
    }

    @Override
    public Result selectRelaxDetail(long frId) {
        return Result.success(foodRelaxDao.selectById(frId));
    }

    @Override
    public Result qureyRelax(FoodRelax foodRelax) {

        IPage page=new Page(foodRelax.getPagenum(),pagesize);
        LambdaQueryWrapper<FoodRelax> lqw = new LambdaQueryWrapper<>();
        if (foodRelax != null) {
            lqw.in(foodRelax.getTypes().size() != 0, FoodRelax::getFrType, foodRelax.getTypes());
            lqw.like(foodRelax.getFrName() != null, FoodRelax::getFrName, foodRelax.getFrName());
            lqw.like(foodRelax.getFrAddr() != null, FoodRelax::getFrAddr, foodRelax.getFrAddr());
            lqw.ge(foodRelax.getRecommendLevel() != null, FoodRelax::getRecommendLevel, foodRelax.getRecommendLevel());
        }

        return Result.success(foodRelaxDao.selectPage(page,lqw).getRecords());
    }

    @Override
    public Result selectAllPerformace(int pagenum) {
        IPage page = new Page(pagenum, pagesize);
        return Result.success(performanceDao.selectPage(page, null).getRecords());

    }

    @Override
    public Result selectPerformaceDetail(long pfId) {
        return Result.success(performanceDao.selectById(pfId));
    }
/*没写完呢,想睡觉*/
    @Override
    public Result queryPerformance(Performance performance) {
//        if (performance.getPfDate()==null){
//            performance.setPfDate(new Timestamp(System.currentTimeMillis()));
//        }
//        System.out.println(performance);
        IPage page=new Page(performance.getPagenum(),pagesize);
        LambdaQueryWrapper<Performance> lqw = new LambdaQueryWrapper<>();
        if (performance != null) {
            lqw.like(performance.getPfTeam() != null, Performance::getPfTeam, performance.getPfTeam());
            lqw.like(performance.getPfName() != null, Performance::getPfName, performance.getPfName());
            lqw.like(performance.getPfAddr() != null, Performance::getPfAddr, performance.getPfAddr());
            lqw.in(performance.getTypes().size() != 0, Performance::getPfType, performance.getTypes());
            //            lqw.between(performance.getPfDate()!=null&&performance.getPfEndDate()!=null,Performance::getPfDate,performance.getPfDate(),performance.getPfEndDate());
            lqw.ge(performance.getPfDate()!=null,Performance::getPfDate,performance.getPfDate());
            lqw.le(performance.getPfEndDate()!=null,Performance::getPfDate,performance.getPfEndDate());
            lqw.ge(performance.getAppropriateAge() != -1, Performance::getAppropriateAge, performance.getAppropriateAge());
            lqw.ge(performance.getRecommendLevel() != -1, Performance::getRecommendLevel, performance.getRecommendLevel());
        }
        return Result.success(performanceDao.selectPage(page,lqw).getRecords());
    }
}